Purchases

class Purchases

Entry point for Purchases. It should be instantiated as soon as your app has a unique user id for your user. This can be when a user logs in if you have accounts or on launch if you can generate a random user identifier. Make sure you follow the quickstart guide to setup your RevenueCat account.

Types

Link copied to clipboard
object Companion
Link copied to clipboard
interface DeepLink

Represents a valid RevenueCat deep link.

Functions

Link copied to clipboard

Creates a support ticket for the current user. Coroutine friendly version of Purchases.createSupportTicket.

Link copied to clipboard
suspend fun Purchases.awaitCustomerCenterConfigData(): <Error class: unknown class>

Gets the current user's CustomerCenterConfigData. Used by RevenueCatUI to present the customer center.

Link copied to clipboard
suspend fun Purchases.awaitCustomerInfo(fetchPolicy: <Error class: unknown class> = CacheFetchPolicy.default()): <Error class: unknown class>

Get latest available customer info. Coroutine friendly version of Purchases.getCustomerInfo.

Link copied to clipboard
suspend fun Purchases.awaitGetVirtualCurrencies(): <Error class: unknown class>

Fetches the virtual currencies for the current subscriber.

Link copied to clipboard
suspend fun Purchases.awaitLogIn(appUserID: String): LogInResult

This function will change the current appUserID. Typically this would be used after a log out to identify a new user without calling configure

Link copied to clipboard
suspend fun Purchases.awaitLogOut(): <Error class: unknown class>

Logs out the Purchases client clearing the save appUserID. This will generate a random user id and save it in the cache.

Link copied to clipboard

This method will try to obtain the Store (Google/Amazon) locale. Note: this locale only has a region set. If there is any error, it will return null and log said error. Coroutine friendly version of Purchases.getStorefrontLocale.

Link copied to clipboard
suspend fun Purchases.awaitSyncAttributesAndOfferingsIfNeeded(): <Error class: unknown class>

Syncs subscriber attributes and then fetches the configured offerings for this user. This method is intended to be called when using Targeting Rules with Custom Attributes. Any subscriber attributes should be set before calling this method to ensure the returned offerings are applied with the latest subscriber attributes.

Link copied to clipboard
suspend fun Purchases.awaitSyncPurchases(): <Error class: unknown class>

This method will send all the purchases to the RevenueCat backend. Call this when using your own implementation for subscriptions anytime a sync is needed, such as when migrating existing users to RevenueCat.

Link copied to clipboard
fun close()

Call close when you are done with this instance of Purchases

Link copied to clipboard
suspend fun Purchases.getAmazonLWAConsentStatus(): <Error class: unknown class>

Note: This method only works for the Amazon Appstore. There is no Google equivalent at this time. Calling from a Google-configured app will always return AmazonLWAConsentStatus.UNAVAILABLE.

Link copied to clipboard
fun Purchases.getAmazonLWAConsentStatusWith(onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (<Error class: unknown class>) -> Unit)

Note: This method only works for the Amazon Appstore. There is no Google equivalent at this time. Calling from a Google-configured app will always return AmazonLWAConsentStatus.UNAVAILABLE.

Link copied to clipboard
fun Purchases.getCustomerInfoWith(onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (<Error class: unknown class>) -> Unit)

Get latest available customer info.

fun Purchases.getCustomerInfoWith(fetchPolicy: <Error class: unknown class>, onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (<Error class: unknown class>) -> Unit)

Get customer info from cache or network depending on fetch policy.

Link copied to clipboard
fun Purchases.getNonSubscriptionSkusWith(skus: List<String>, onError: (<Error class: unknown class>) -> Unit, onReceiveSkus: (storeProducts: List<<Error class: unknown class>>) -> Unit)

Gets the StoreProduct for the given list of non-subscription skus.

Link copied to clipboard
fun getOfferings(listener: <Error class: unknown class>)

Fetch the configured offerings for this users. Offerings allows you to configure your in-app products vis RevenueCat and greatly simplifies management. See the guide for more info.

Link copied to clipboard
fun getProducts(productIds: List<String>, callback: <Error class: unknown class>)

Gets the StoreProduct(s) for the given list of product ids for all product types.

fun getProducts(productIds: List<String>, type: <Error class: unknown class>? = null, callback: <Error class: unknown class>)

Gets the StoreProduct(s) for the given list of product ids of type type

Link copied to clipboard
fun getStorefrontCountryCode(callback: <Error class: unknown class>)

This method will try to obtain the Store (Google/Amazon) country code in ISO-3166-1 alpha2. If there is any error, it will return null and log said error.

Link copied to clipboard
fun Purchases.getStorefrontLocaleWith(onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (storefrontLocale: Locale) -> Unit)

This method will try to obtain the Store (Google/Amazon) locale. Note: this locale only has a region set. If there is any error, it will return null and log said error.

Link copied to clipboard
fun Purchases.getSubscriptionSkusWith(skus: List<String>, onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onReceiveSkus: (storeProducts: List<<Error class: unknown class>>) -> Unit)

Gets the SKUDetails for the given list of subscription skus.

Link copied to clipboard
fun Purchases.getVirtualCurrenciesWith(onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (<Error class: unknown class>) -> Unit)

Fetches the virtual currencies for the current subscriber.

Link copied to clipboard
fun Purchases.logInWith(appUserID: String, onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (<Error class: unknown class>, created: Boolean) -> Unit)

This function will change the current appUserID. Typically this would be used after a log out to identify a new user without calling configure

Link copied to clipboard
fun Purchases.logOutWith(onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (<Error class: unknown class>) -> Unit)

Logs out the Purchases client clearing the save appUserID. This will generate a random user id and save it in the cache.

Link copied to clipboard
fun purchase(purchaseParams: <Error class: unknown class>, callback: <Error class: unknown class>)

Initiate a purchase with the given PurchaseParams. Initialized with an Activity either a Package, StoreProduct, or SubscriptionOption.

Link copied to clipboard
fun Purchases.purchasePackageWith(activity: Activity, packageToPurchase: Package, onError: (<Error class: unknown class>, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB, onSuccess: (<Error class: unknown class>, <Error class: unknown class>) -> Unit)

Make a purchase. If purchasing a subscription, it will choose the default SubscriptionOption.

Link copied to clipboard
fun Purchases.purchaseProductWith(activity: Activity, storeProduct: <Error class: unknown class>, onError: (<Error class: unknown class>, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB, onSuccess: (<Error class: unknown class>, <Error class: unknown class>) -> Unit)

Purchase product. If purchasing a subscription, it will choose the default SubscriptionOption.

Link copied to clipboard

Call this when you are finished using the UpdatedCustomerInfoListener. You should call this to avoid memory leaks.

Link copied to clipboard
fun restorePurchases(callback: <Error class: unknown class>)

Restores purchases made with the current Play Store account for the current user. This method will post all active subscriptions and non consumed one time purchases associated with the current Play Store account to RevenueCat and become associated with the current appUserID. If the receipt token is being used by an existing user, the current appUserID will be aliased together with the appUserID of the existing user. Going forward, either appUserID will be able to reference the same user.

Link copied to clipboard
fun showInAppMessagesIfNeeded(activity: Activity, inAppMessageTypes: List<<Error class: unknown class>> = listOf(InAppMessageType.BILLING_ISSUES))

Google Play only, no-op for Amazon. Displays the specified in-app message types to the user as a snackbar if there are any available to be shown. If PurchasesConfiguration.showInAppMessagesAutomatically is enabled, this will be done automatically on each Activity's onStart.

Link copied to clipboard
fun switchUser(newAppUserID: String)

Updates the current appUserID to a new one, without associating the two.

Link copied to clipboard
fun Purchases.syncAttributesAndOfferingsIfNeededWith(onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (<Error class: unknown class>) -> Unit)

Syncs subscriber attributes and then fetches the configured offerings for this user. This method is intended to be called when using Targeting Rules with Custom Attributes. Any subscriber attributes should be set before calling this method to ensure the returned offerings are applied with the latest subscriber attributes.

Link copied to clipboard
fun Purchases.syncPurchasesWith(onError: (<Error class: unknown class>) -> Unit = ON_ERROR_STUB, onSuccess: (<Error class: unknown class>) -> Unit)

This method will send all the purchases to the RevenueCat backend. Call this when using your own implementation for subscriptions anytime a sync is needed, such as when migrating existing users to RevenueCat. The onSuccess callback will be called if all purchases have been synced successfully or there are no purchases. Otherwise, the onError callback will be called with a PurchasesError indicating the first error found.

Properties

Link copied to clipboard

The passed in or generated app user ID

Link copied to clipboard
Link copied to clipboard
var updatedCustomerInfoListener: <Error class: unknown class>?

The listener is responsible for handling changes to customer information. Make sure removeUpdatedCustomerInfoListener is called when the listener needs to be destroyed.